home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / appshell / appprset.frm < prev    next >
Text File  |  1995-09-06  |  6KB  |  220 lines

  1. VERSION 2.00
  2. Begin Form AppPrSetup 
  3.    BorderStyle     =   3  'Fixed Double
  4.    Caption         =   "Printer Setup"
  5.    ClientHeight    =   2010
  6.    ClientLeft      =   360
  7.    ClientTop       =   2310
  8.    ClientWidth     =   5100
  9.    Height          =   2415
  10.    Left            =   300
  11.    LinkMode        =   1  'Source
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   2010
  16.    ScaleWidth      =   5100
  17.    Top             =   1965
  18.    Width           =   5220
  19.    Begin CommandButton SetupCmd 
  20.       Caption         =   "&Setup..."
  21.       Height          =   315
  22.       Left            =   3900
  23.       TabIndex        =   3
  24.       Top             =   1440
  25.       Width           =   1035
  26.    End
  27.    Begin CommandButton CancelCmd 
  28.       Cancel          =   -1  'True
  29.       Caption         =   "Cancel"
  30.       Height          =   315
  31.       Left            =   3900
  32.       TabIndex        =   2
  33.       Top             =   540
  34.       Width           =   1035
  35.    End
  36.    Begin ListBox PrinterList 
  37.       Height          =   1395
  38.       Left            =   120
  39.       Sorted          =   -1  'True
  40.       TabIndex        =   4
  41.       Top             =   420
  42.       Width           =   3615
  43.    End
  44.    Begin CommandButton OKCmd 
  45.       Caption         =   "OK"
  46.       Default         =   -1  'True
  47.       Height          =   315
  48.       Left            =   3900
  49.       TabIndex        =   1
  50.       Top             =   120
  51.       Width           =   1035
  52.    End
  53.    Begin Label PrinterLabel 
  54.       Caption         =   "&Printer:"
  55.       Height          =   255
  56.       Left            =   120
  57.       TabIndex        =   0
  58.       Top             =   120
  59.       Width           =   735
  60.    End
  61. End
  62. Dim PrinterName(10) As String
  63. Dim DriverName(10)  As String
  64. Dim PortName(10)    As String
  65.  
  66.  
  67.  
  68. Sub CancelCmd_Click ()
  69.   
  70.   Unload AppPrSetup
  71.  
  72. End Sub
  73.  
  74. Sub Form_Load ()
  75.   
  76.   Dim SelPrName As String
  77.  
  78.   Remove_Items_From_SysMenu AppPrSetup
  79.   Place_DialogBox_in_Form AppPrSetup, AppMain
  80.  
  81.   If App_PrSetupTitle = "" Then
  82.     App_PrSetupTitle = "Printer Setup"
  83.   End If
  84.   AppPrSetup.Caption = App_PrSetupTitle
  85.   
  86.   '
  87.   ' empty the printer list box
  88.   '
  89.   Do While PrinterList.ListCount
  90.     PrinterList.RemoveItem 0
  91.   Loop
  92.   
  93.   '
  94.   ' if no currently selected printer, use the default
  95.   '
  96.   If App_PrinterName = "" Then
  97.     buf$ = String$(2048, 0)
  98.     BufSize% = Len(buf$)
  99.     y% = GetProfileString("windows", ByVal "device", "Error", buf$, BufSize%)
  100.     If buf$ <> "Error" Then
  101.       SelPrName = Left$(buf$, InStr(buf$, ",") - 1)
  102.     End If
  103.   Else
  104.     SelPrName = App_PrinterName
  105.   End If
  106.  
  107.   '
  108.   ' get the new list of printers
  109.   '
  110.   buf$ = String$(2048, 0)
  111.   y% = GetProfileString("devices", ByVal 0&, "Error", buf$, BufSize%)
  112.   
  113.   '
  114.   ' parse list and load list box
  115.   '
  116.   i% = -1  ' number of printers loaded
  117.   j% = 1
  118.   k% = InStr(j%, buf$, Chr$(0))     ' end index into buffer
  119.  
  120.   While (k% <> 0 And j% < k%)
  121.     LoadPrinterList Mid$(buf$, j%, k% - j%), i%
  122.     j% = k% + 1
  123.     k% = InStr(j%, buf$, Chr$(0))
  124.   Wend
  125.   
  126.   If i% < 0 Then
  127.     MsgBox "No Printers Found", MB_ICONSTOP, AppPrSetup.Caption
  128.   Else
  129.     '
  130.     ' highlight currently selected printer in list box
  131.     '
  132.     For j% = 0 To i%
  133.       If Left$(PrinterList.List(j%), Len(SelPrName)) = SelPrName Then
  134.         PrinterList.ListIndex = j%
  135.         Exit For
  136.       End If
  137.     Next
  138.   End If
  139.  
  140. End Sub
  141.  
  142. Sub LoadPrinterList (PrName As String, PrNum As Integer)
  143.  
  144.     buf$ = String$(80, 0)
  145.     BufSize% = Len(buf$)
  146.     key$ = PrName
  147.     '
  148.     ' find out the driver name and port name
  149.     '
  150.     y% = GetProfileString("devices", ByVal key$, "Error", buf$, BufSize%)
  151.     buf$ = Left$(buf$, InStr(buf$, Chr$(0)) - 1)
  152.     i% = InStr(buf$, ",")
  153.     If i% > 0 Then
  154.       a$ = Left$(buf$, i% - 1)
  155.       b$ = Right$(buf$, Len(buf$) - i%)
  156.       If b$ <> "None" Then
  157.         PrinterList.AddItem key$ + " on " + b$
  158.         PrNum = PrNum + 1
  159.         PrinterName(PrNum) = PrName
  160.         DriverName(PrNum) = a$
  161.         PortName(PrNum) = b$
  162.       End If
  163.     End If
  164.  
  165. End Sub
  166.  
  167. Sub OKCmd_Click ()
  168.   
  169.   x% = PrinterList.ListIndex
  170.   If x% < 0 Then
  171.     MsgBox "Must select a printer", MB_ICONINFORMATION, AppPrSetup.Caption
  172.   Else
  173.     For x% = 0 To 10
  174.       If Left$(PrinterList.Text, Len(PrinterName(x%))) = PrinterName(x%) Then Exit For
  175.     Next
  176.     App_PrinterName = PrinterName(x%)
  177.     App_PrinterDriver = DriverName(x%)
  178.     App_PrinterPort = PortName(x%)
  179.     Unload AppPrSetup
  180.   End If
  181.  
  182. End Sub
  183.  
  184. Sub PrinterList_DblClick ()
  185.   OKCmd_Click
  186. End Sub
  187.  
  188. Sub SetupCmd_Click ()
  189.   
  190.   x% = PrinterList.ListIndex
  191.   If x% < 0 Then
  192.     MsgBox "Must select a printer", MB_ICONINFORMATION, AppPrSetup.Caption
  193.   Else
  194.     '
  195.     ' determine printer to setup
  196.     '
  197.     For x% = 0 To 10
  198.       If Left$(PrinterList.Text, Len(PrinterName(x%))) = PrinterName(x%) Then Exit For
  199.     Next
  200.     '
  201.     ' call app shell dll routine to display printer setup dialog box
  202.     '
  203.     prn$ = PrinterName(x%)
  204.     dn$ = DriverName(x%) + ".drv"
  205.     pn$ = PortName(x%)
  206.     handle% = LoadLibrary("APPSHELL.DLL")
  207.     If handle% >= 32 Then
  208.       r% = AppShellPrSetup(AppPrSetup.hwnd, prn$, dn$, pn$)
  209.       If Not r% Then
  210.         MsgBox "Can't run printer setup;" + CRLF + "please check your installation", MB_ICONEXCLAMATION, APP_NAME
  211.       End If
  212.       FreeLibrary handle%
  213.     Else
  214.       MsgBox "Can't find printer setup program;" + CRLF + "reason code =" + Str$(handle%) + ";" + CRLF + "please check your software installation", MB_ICONEXCLAMATION, APP_NAME
  215.     End If
  216.   End If
  217.  
  218. End Sub
  219.  
  220.